package com.example.community.util;

import com.example.community.entity.TextContentEs;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@Slf4j
@Service
public class RestTemplateUtil {
    @Resource
    RestTemplate restTemplate;

    public Object postForEntity(String url, Object body) {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
//        String url="http://localhost:8081/community/textContent/findAllEs";
//        new
//        final TextContentEs textContentEs = new TextContentEs();
//        textContentEs.setContent("demo textContentEs");
        HttpEntity request1 = new HttpEntity<>(body, headers);
        log.info("请求报文：{}", body);
//————————————————
//        版权声明：本文为CSDN博主「海枯石烂i」的原创文章，遵循CC 4.0 BY-SA版权协议，转载请附上原文出处链接及本声明。
//        原文链接：https://blog.csdn.net/Lifeime/article/details/123043219
        ResponseEntity<Object> forEntity =
                restTemplate.postForEntity(url, request1, Object.class);
        return forEntity;

    }
}
